package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.ArrayList;


public class Library {
    ArrayList<Book> library = new ArrayList<Book>();
    ArrayList<Movie> movies = new ArrayList<Movie>();

    Library(){
        this.addBook(new Book("The Information: A History, a Theory, a Flood"));
        this.addBook(new Book("Designing With the Mind in Mind"));
        this.addBook(new Book("The Castle"));
        this.addBook(new Book("Anna Karenina"));
        this.addBook(new Book("The Picture of Dorian Gray"));
        this.generateMovies();
    }
    void printBooks(PrintStream printStream) {
        for(int i = 0; i < library.size(); i++){
           Integer num = i;
           printStream.println(num.toString() + ". "+ library.get(i).getBookName()+"");
        }
         printStream.println("");
    }

    public Book getBook(int index){
        return library.get(index);
    }

    public void addBook(Book book){
        library.add(book);
    }

    public void reserveBook(int index){
        Book book = library.get(index);
        if(!book.isReserved()){
            book.setReserved(true);
            System.out.println("Thank You! Enjoy the book.\n");
        }   else{
            System.out.println("Sorry we don't have that book yet.");

        }
    }

    boolean validateIndex(int index){
        boolean isValid;
        isValid = index >= 0 && index < library.size();
        return isValid;
    }

    public void generateMovies() {
         movies.add(new Movie("Black Swan", 2010, "Darren Aronofsky", "0"));
         movies.add(new Movie("Inception", 2010, "Christopher Nolan", "13"));
         movies.add(new Movie("The Pianist", 2010, "Roman Polanski", "12"));
         movies.add(new Movie("The Dark Knight Rises", 2012, "Christopher Nolan", "0"));
         movies.add(new Movie("WALL·E", 2008, "Andrew Stanton", "10"));
         movies.add(new Movie("The Intouchables", 2011, "Olivier Nakache", "14"));
         movies.add(new Movie("The King's Speech", 2010, "Tom Hooper", "15"));
         movies.add(new Movie("Life of Pi", 2012, "Ang Lee", "10"));
         movies.add(new Movie("The Artist", 2011, "Michel Hazanavicius", "0"));
         movies.add(new Movie("District 9", 2009, "Neill Blomkamp", "10"));

         movies.add(new Movie("Pride & Prejudice", 2005, "Joe Wright", "15"));
         movies.add(new Movie("Never Let Me Go", 2010, "Mark Romanek", "10"));
         movies.add(new Movie("Doctor Zhivago", 2012, "Giacomo Campiotti", "13"));
         movies.add(new Movie("Memoirs of a Geisha", 2005, "Rob Marshall", "10"));
         movies.add(new Movie("The Great Gatsby", 2013, "Baz Luhrmann", "14"));

    }

    public void printMovies(PrintStream stream) {
        stream.printf("%-22s %-10s %-22s %-5s\n", "Title", "Year", "Director", "Rating");
        for(int i = 0; i < movies.size(); i++){
            stream.printf("%-22s %-10s %-22s %-5s\n", movies.get(i).getName(), movies.get(i).getYear(), movies.get(i).getDirector(), movies.get(i).getRating());
        }
        stream.println("\n");
    }
}
